<!DOCTYPE html>
<html lang="en">

	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>文件上传</title>

		<meta name="description" content="Common form elements and layouts" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />

		<!-- bootstrap & fontawesome -->
		<link rel="stylesheet" href="/assets/css/bootstrap.min.css" />
		<link rel="stylesheet" href="/assets/font-awesome/4.5.0/css/font-awesome.min.css" />

		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="/assets/css/jquery-ui.custom.min.css" />
		<link rel="stylesheet" href="/assets/css/chosen.min.css" />
		<link rel="stylesheet" href="/assets/css/bootstrap-datepicker3.min.css" />
		<link rel="stylesheet" href="/assets/css/bootstrap-timepicker.min.css" />
		<link rel="stylesheet" href="/assets/css/daterangepicker.min.css" />
		<link rel="stylesheet" href="/assets/css/bootstrap-datetimepicker.min.css" />
		<link rel="stylesheet" href="/assets/css/bootstrap-colorpicker.min.css" />

		<!-- text fonts -->
		<link rel="stylesheet" href="/assets/css/fonts.googleapis.com.css" />

		<!-- ace styles -->
		<link rel="stylesheet" href="/assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />

		<!--[if lte IE 9]>
			<link rel="stylesheet" href="/assets/css/ace-part2.min.css" class="ace-main-stylesheet" />
		<![endif]-->
		<link rel="stylesheet" href="/assets/css/ace-skins.min.css" />
		<link rel="stylesheet" href="/assets/css/ace-rtl.min.css" />
		<link rel="stylesheet" href="/assets/css/select2.min.css" media="screen" />

		<!--[if lte IE 9]>
		  <link rel="stylesheet" href="/assets/css/ace-ie.min.css" />
		<![endif]-->

		<!-- inline styles related to this page -->

		<!-- ace settings handler -->
		<script src="/assets/js/ace-extra.min.js"></script>

		<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->

		<!--[if lte IE 8]>
		<script src="/assets/js/html5shiv.min.js"></script>
		<script src="/assets/js/respond.min.js"></script>
		<![endif]-->
	</head>

	<body class="no-skin">
		<div id="navbar" class="navbar navbar-default          ace-save-state">
			<div class="navbar-container ace-save-state" id="navbar-container">
				<button type="button" class="navbar-toggle menu-toggler pull-left" id="menu-toggler" data-target="#sidebar">
					<span class="sr-only">Toggle sidebar</span>

					<span class="icon-bar"></span>

					<span class="icon-bar"></span>

					<span class="icon-bar"></span>
				</button>

				<div class="navbar-header pull-left">
					<a href="/views/index.html" class="navbar-brand">
						<small>
							<i class="fa fa-leaf"></i>
							学生发展数据综合评价与分析系统
						</small>
					</a>
				</div>

				<div class="navbar-buttons navbar-header pull-right" role="navigation">
					<ul class="nav ace-nav">

						<li class="light-blue dropdown-modal">
							<a data-toggle="dropdown" href="#" class="dropdown-toggle">

								<img class="nav-user-photo us_photo" src="/assets/images/avatars/blank.jpg" alt="个人头像" style="background-color:#fff" />

								<span class="user-info">
							       <span id="us_name"></span>
								</span>

								<i class="ace-icon fa fa-caret-down"></i>
							</a>

							<ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
								<li>
									<a id="setting" target="_blank">
										<i class="ace-icon fa fa-cog"></i> 设置
									</a>
								</li>

								<li>
									<a id="profile" target="_blank">
										<i class="ace-icon fa fa-user"></i> 个人信息
									</a>
								</li>

								<li class="divider"></li>

								<li>
									<a href="/login.html" onclick="logout()">
										<i class="ace-icon fa fa-power-off"></i> 注销
									</a>
								</li>
							</ul>
						</li>
					</ul>
				</div>
			</div>
			<!-- /.navbar-container -->
		</div>

		<div class="main-container ace-save-state" id="main-container">
			<script type="text/javascript">
				try {
					ace.settings.loadState('main-container')
				} catch(e) {}
			</script>

			<div id="sidebar" class="sidebar                  responsive                    ace-save-state">
				<script type="text/javascript">
					try {
						ace.settings.loadState('sidebar')
					} catch(e) {}
				</script>

				<div class="sidebar-shortcuts" id="sidebar-shortcuts">
					<div class="sidebar-shortcuts-large" id="sidebar-shortcuts-large">
						<button class="btn btn-success">
							<i class="ace-icon fa fa-signal"></i>
						</button>

						<button class="btn btn-info">
							<i class="ace-icon fa fa-pencil"></i>
						</button>

						<button class="btn btn-warning">
							<i class="ace-icon fa fa-users"></i>
						</button>

						<button class="btn btn-danger">
							<i class="ace-icon fa fa-cogs"></i>
						</button>
					</div>

					<div class="sidebar-shortcuts-mini" id="sidebar-shortcuts-mini">
						<span class="btn btn-success"></span>

						<span class="btn btn-info"></span>

						<span class="btn btn-warning"></span>

						<span class="btn btn-danger"></span>
					</div>
				</div>
				<!-- /.sidebar-shortcuts -->
				<ul class="nav nav-list">
					<li class="">
						<a href="/views/index.html">
							<i class="menu-icon fa fa-tachometer"></i>
							<span class="menu-text"> 我的首页 </span>
						</a>

						<b class="arrow"></b>
					</li>

					<li class="">
						<a href="#" class="dropdown-toggle">
							<i class="menu-icon fa fa-tasks"></i>
							<span class="menu-text"> 数据管理 </span>

							<b class="arrow fa fa-angle-down"></b>
						</a>

						<b class="arrow"></b>

						<ul class="submenu">

							<li class="">
								<a href="/views/dataManage/studentManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 学生
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/teacherManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 教师
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/majorManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 专业
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/classroomManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 班级
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/scoreManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 成绩
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/certificateManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 证书
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/competitionManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 竞赛
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/innovationTrainManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 创新训练
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/scholarshipManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 奖学金
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/excellentStudentManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 优秀学生
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/pushExcellentManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 推优
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/partyMemberManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 入党
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/postGraduateManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 考研录取
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/volunteerManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 志愿服务
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/dutyManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 学生干部
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/dataManage/adviceManage.html">
									<i class="menu-icon fa fa-caret-right"></i> 发展建议
								</a>

								<b class="arrow"></b>
							</li>

						</ul>
					</li>

					<li class="">
						<a href="#" class="dropdown-toggle">
							<i class="menu-icon fa fa-bar-chart-o"></i>
							<span class="menu-text"> 数据分析 </span>

							<b class="arrow fa fa-angle-down"></b>
						</a>

						<b class="arrow"></b>

						<ul class="submenu">
							<li class="">
								<a href="#" class="dropdown-toggle">
									<i class="menu-icon fa fa-caret-right"></i> 个人情况分析
									<b class="arrow fa fa-angle-down"></b>
								</a>

								<b class="arrow"></b>

								<ul class="submenu">
									<li class="">
										<a href="/views/dataAnalysis/student/personalGrade.html">
											<i class="menu-icon fa fa-leaf green"></i>个人成绩查询
										</a>

										<b class="arrow"></b>
									</li>
									<li class="">
										<a href="/views/dataAnalysis/student/personalAllInfo.html">
											<i class="menu-icon fa fa-leaf green"></i>发展综合分析
										</a>

										<b class="arrow"></b>
									</li>

								</ul>
							</li>

							<li class="">
								<a href="/views/dataAnalysis/dorm/dormAtmosphere.html">
									<i class="menu-icon fa fa-caret-right"></i> 宿舍情况分析
								</a>

								<b class="arrow"></b>
							</li>

							<li class="">
								<a href="/views/dataAnalysis/classroom/classAtmosphere.html">
									<i class="menu-icon fa fa-caret-right"></i> 班级情况分析
								</a>

								<b class="arrow"></b>
							</li>

							<li class="">
								<a href="#" class="dropdown-toggle">
									<i class="menu-icon fa fa-caret-right"></i> 整体学业分析
									<b class="arrow fa fa-angle-down"></b>
								</a>

								<b class="arrow"></b>

								<ul class="submenu">
									<li class="">
										<a href="/views/dataAnalysis/all/allGrade.html">
											<i class="menu-icon fa fa-leaf green"></i>学分积欠情况分析
										</a>

										<b class="arrow"></b>
									</li>
									<li class="">
										<a href="/views/dataAnalysis/all/make_up_rebuild.html">
											<i class="menu-icon fa fa-leaf green"></i>补考重修情况分析
										</a>

										<b class="arrow"></b>
									</li>

								</ul>
							</li>

						</ul>
					</li>

					<li class="">
						<a href="#" class="dropdown-toggle">
							<i class="menu-icon fa fa-book"></i>
							<span class="menu-text"> 数据预测 </span>

							<b class="arrow fa fa-angle-down"></b>
						</a>

						<b class="arrow"></b>

						<ul class="submenu">
							<li class="">
								<a href="/views/bigDataAnalysis/courseDependence.html">
									<i class="menu-icon fa fa-caret-right"></i> 课程通过预警
								</a>

								<b class="arrow"></b>
							</li>

							<li class="">
								<a href="/views/bigDataAnalysis/scorePosition.html">
									<i class="menu-icon fa fa-caret-right"></i> 成绩位置预测
								</a>

								<b class="arrow"></b>
							</li>

							<li class="">
								<a href="/views/bigDataAnalysis/postGraduate.html">
									<i class="menu-icon fa fa-caret-right"></i> 考研录取预测
								</a>

								<b class="arrow"></b>
							</li>

							<li class="">
								<a href="/views/bigDataAnalysis/partyMember.html">
									<i class="menu-icon fa fa-caret-right"></i> 入党情况预测
								</a>

								<b class="arrow"></b>
							</li>

						</ul>
					</li>

					<li class="active open">
						<a href="#" class="dropdown-toggle">
							<i class="menu-icon fa fa-folder-open-o"></i>
							<span class="menu-text"> 文件操作 </span>

							<b class="arrow fa fa-angle-down"></b>
						</a>

						<b class="arrow"></b>

						<ul class="submenu">
							<li class="active">
								<a href="/views/file/fileUpload.html">
									<i class="menu-icon fa fa-caret-right"></i> 文件上传
								</a>

								<b class="arrow"></b>
							</li>
							<li class="">
								<a href="/views/file/fileDownload.html">
									<i class="menu-icon fa fa-caret-right"></i> 文件下载
								</a>

								<b class="arrow"></b>
							</li>

						</ul>
					</li>

				</ul>
				<!-- /.nav-list -->

				<div class="sidebar-toggle sidebar-collapse" id="sidebar-collapse">
					<i id="sidebar-toggle-icon" class="ace-icon fa fa-angle-double-left ace-save-state" data-icon1="ace-icon fa fa-angle-double-left" data-icon2="ace-icon fa fa-angle-double-right"></i>
				</div>
			</div>

			<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="/views/index.html">我的主页</a>
							</li>

							<li class="active">文件上传</li>
						</ul>
						<!-- /.breadcrumb -->

					</div>

					<div class="page-content">

						<div class="page-header">
							<h1>
								文件上传
								<small>
									<i class="ace-icon fa fa-angle-double-right"></i>
									<span style="font-size: 16px;">可支持同时上传多份文件</span>
								</small>
							</h1>
						</div>
						<!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<form class="form-horizontal" role="form" enctype="multipart/form-data" id="fileForm">

									<div class="row">

										<!-- /.span -->

										<div class="col-xs-12 col-sm-4">
											<div class="widget-box">
												<div class="widget-header">
													<h4 class="widget-title">填写需要上传的文件信息</h4>

													<span class="widget-toolbar">
													

													
													

														
													</span>
												</div>

												<div class="widget-body">
													<div class="widget-main">

														<div style="margin-bottom: 12px;">
															<label for="fi_grade" style="margin-bottom: 8px;">文件所属年级</label>
															<select class="form-control" id="fi_grade">

															</select>
														</div>
														<div style="margin-bottom: 12px;">
															<label for="fi_major" style="margin-bottom: 8px;">文件所属专业</label>
															<select class="form-control" id="fi_major">

															</select>
														</div>
														<div style="margin-bottom: 12px;">
															<label for="fi_class" style="margin-bottom: 8px;">文件所属班级</label>
															<select class="form-control" id="fi_class">

															</select>
														</div>
														<div style="margin-bottom: 12px;">
															<label for="fi_course" style="margin-bottom: 8px;">文件所属课程</label>
															<select class="form-control" id="fi_course" class="select2">

															</select>
														</div>
														<div class="form-group" style="margin-top: 20px;">
															<div class="col-xs-12">
																<input multiple="" type="file" id="files" />
															</div>
														</div>

														<div style="margin-bottom: 12px;">
															<label for="fi_info" style="margin-bottom: 8px;">文件简介</label>
															<textarea id="fi_info" class="autosize-transition form-control"></textarea>
														</div>

														<div class="clearfix form-actions">
															<div class="col-md-offset-3 col-md-9">
																<button class="btn btn-info" type="button" id="fileCommit">
											                    	<i class="ace-icon fa fa-check bigger-110"></i>
												                                                  确定上传
											                     </button> &nbsp; &nbsp; &nbsp;
																<button class="btn" type="reset">
												                    <i class="ace-icon fa fa-undo bigger-110"></i>
												                                                      重置
											                    </button>
															</div>
														</div>

													</div>
												</div>
											</div>
										</div>
										<!-- /.span -->
									</div>
									<!-- /.row -->

									<div class="space-24"></div>

									<div class="hr hr-24"></div>

								</form>

								<div class="hr hr-18 dotted hr-double"></div>

								<!-- PAGE CONTENT ENDS -->
							</div>
							<!-- /.col -->
						</div>
						<!-- /.row -->
					</div>
					<!-- /.page-content -->
				</div>
			</div>
			<!-- /.main-content -->

			<div class="footer">
				<div class="footer-inner">
					<div class="footer-content">
						<span class="bigger-120">
							<span class="blue bolder" style="margin-right: 10px;">学生发展数据综合评价与分析系统</span> 苏州科技大学 &copy; 2018-2019
						</span>

					</div>
				</div>
			</div>

			<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
				<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
			</a>
		</div>
		<!-- /.main-container -->

		<!-- basic scripts -->

		<!--[if !IE]> -->
		<script src="/assets/js/jquery-2.1.4.min.js"></script>
		<script src="/assets/js/jquery.form.js"></script>
		<script src="/assets/js/jquery.cookie.js"></script>
		<script src="/assets/js/sddb.util.js"></script>
		<script src="/assets/js/select2.min.js"></script>
		<script src="/assets/js/jquery.cookie.js"></script>

		<!-- <![endif]-->

		<!--[if IE]>
<script src="/assets/js/jquery-1.11.3.min.js"></script>
<![endif]-->
		<script type="text/javascript">
			if('ontouchstart' in document.documentElement) document.write("<script src='/assets/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
		</script>
		<script src="/assets/js/bootstrap.min.js"></script>

		<!-- page specific plugin scripts -->

		<!--[if lte IE 8]>
		  <script src="/assets/js/excanvas.min.js"></script>
		<![endif]-->
		<script src="/assets/js/jquery-ui.custom.min.js"></script>
		<script src="/assets/js/jquery.ui.touch-punch.min.js"></script>
		<script src="/assets/js/chosen.jquery.min.js"></script>
		<script src="/assets/js/spinbox.min.js"></script>
		<script src="/assets/js/bootstrap-datepicker.min.js"></script>
		<script src="/assets/js/bootstrap-timepicker.min.js"></script>
		<script src="/assets/js/moment.min.js"></script>
		<script src="/assets/js/daterangepicker.min.js"></script>
		<script src="/assets/js/bootstrap-datetimepicker.min.js"></script>
		<script src="/assets/js/bootstrap-colorpicker.min.js"></script>
		<script src="/assets/js/jquery.knob.min.js"></script>
		<script src="/assets/js/autosize.min.js"></script>
		<script src="/assets/js/jquery.inputlimiter.min.js"></script>
		<script src="/assets/js/jquery.maskedinput.min.js"></script>
		<script src="/assets/js/bootstrap-tag.min.js"></script>

		<!-- ace scripts -->
		<script src="/assets/js/ace-elements.min.js"></script>
		<script src="/assets/js/ace.min.js"></script>

		<!--选择年份、班级、专业-->
		<script type="text/javascript">
			//总体数据
			var arrayGrade = [];

			//判断数组中是否存在此数
			function isExist(array, n) {
				for(var i = 0; i < array.length; i++) {
					if(array[i] == n) {
						return true;
					}
				}
				return false;

			}
			//先得到年级
			function getGrade(arrayGrade) {

				var grade = [""];
				for(var i = 0; i < arrayGrade.length; i++) {
					//先判断grade中是否存在该数字
					var grade_item = arrayGrade[i].cl_grade;
					if(!isExist(grade, grade_item)) {
						grade.push(grade_item);
					}
				}
				//遍历grade数组，将值填入进年级下拉框中
				var sel_grade = document.getElementById("fi_grade");
				for(var j = 0; j < grade.length; j++) {
					var temp = grade[j];
					sel_grade.options[j] = new Option(temp, temp);
				}
			}

			//st_grade的改变事件
			$("#fi_grade").change(function() {
				var major = [""];
				var grade = $("#fi_grade option:selected").val();

				//取出指定年级的不重复的专业
				for(var i = 0; i < arrayGrade.length; i++) {
					var temp_grade = arrayGrade[i].cl_grade;
					var temp_major = arrayGrade[i].cl_major;

					if((temp_grade == grade) && (!isExist(major, temp_major))) {
						major.push(temp_major);
					}
				}

				var sel_major = document.getElementById("fi_major");
				//清空之前的专业、班级、课程下拉框
				$("#fi_major").empty();
				$("#fi_class").empty();
				$("#fi_course").empty();

				for(var j = 0; j < major.length; j++) {
					sel_major.options[j] = new Option(major[j], major[j]);
				}
			});

			//fi_major的改变事件

			$("#fi_major").change(function() {

				var sclass = [""];
				var grade = $("#fi_grade option:selected").val();
				var major = $("#fi_major option:selected").val();

				//取出指定年级、专业的班级
				for(var i = 0; i < arrayGrade.length; i++) {
					var temp_grade = arrayGrade[i].cl_grade;
					var temp_major = arrayGrade[i].cl_major;
					if((temp_grade == grade) && (temp_major == major)) {
						sclass.push(arrayGrade[i].cl_name);
					}
				}

				///清空之前的班级、课程下拉框
				$("#fi_class").empty();
				$("#fi_course").empty();

				var sel_class = document.getElementById("fi_class");
				for(var j = 0; j < sclass.length; j++) {
					sel_class.options[j] = new Option(sclass[j], sclass[j]);
				}
			});

			//fi_class的改变事件
			$("#fi_class").change(function() {
				$.ajax({
					type: "post",
					url: "/file/findClass.do",
					dataType: "json",
					data: {
						"sc_class_name": $("#fi_class").val()
					},
					success: function(data) {
						//document.getElementById("fi_course").innerHTML = "";
						//$("#fi_course_chosen > div > ul").html("");

						$("#fi_course").empty();

						//将数据填充到下拉框中
						var sel_course = document.getElementById("fi_course");
						var i = 0;
						for(var str in data) {
							sel_course.options[i] = new Option(data[str], data[str]);
							i++;
						}

						//初始化select2
						$("#fi_course").select2();

					},
					error: function(err) {

					}
				});
			});

			$(function() {

				//ajax请求获取班级
				$.ajax({
					type: "post",
					url: "/score/getClassroom.do",
					dataType: "json",
					data: {},
					success: function(data) {
						arrayGrade = data;
						getGrade(data);

					},
					error: function() {
						alert("获取信息失败!");
					}
				});
			})
		</script>

		<!--文件上传-->
		<script type="text/javascript">
			jQuery(function($) {
				$("#fileCommit").click(function() {
					var formData = new FormData();
					var files = $("#files")[0].files;
					for(var i = 0; i < files.length; i++) {
						formData.append("files", files[i]);
					}
					formData.append("fi_user_id", $.cookie("us_id"));
					formData.append("fi_grade", $("#fi_grade").val());
					formData.append("fi_major", $("#fi_major").val());
					formData.append("fi_info", $("#fi_info").val());
					formData.append("fi_course", $("#fi_course").val())

					$.ajax({
						type: "post",
						url: "/file/fileUpload.do",
						data: formData,
						cache: false,
						processData: false,
						contentType: false,

						success: function(data) {
							if(data.success) {
								alert("上传成功!");
							}

						},
						error: function(err) {
							alert("文件上传遇到错误!" + JSON.stringify(err));
						}

					});
				})
			});
		</script>

		<!-- inline scripts related to this page -->
		<script type="text/javascript">
			function setSelect() {
				if(!ace.vars['touch']) {
					$('.chosen-select').chosen({
						allow_single_deselect: true
					});
					//resize the chosen on window resize

					$(window)
						.off('resize.chosen')
						.on('resize.chosen', function() {
							$('.chosen-select').each(function() {
								var $this = $(this);
								$this.next().css({
									'width': $this.parent().width()
								});
							})
						}).trigger('resize.chosen');
					//resize chosen on sidebar collapse/expand
					$(document).on('settings.ace.chosen', function(e, event_name, event_val) {
						if(event_name != 'sidebar_collapsed') return;
						$('.chosen-select').each(function() {
							var $this = $(this);
							$this.next().css({
								'width': $this.parent().width()
							});
						})
					});

					$('#chosen-multiple-style .btn').on('click', function(e) {
						var target = $(this).find('input[type=radio]');
						var which = parseInt(target.val());
						if(which == 2) $('#form-field-select-4').addClass('tag-input-style');
						else $('#form-field-select-4').removeClass('tag-input-style');
					});
				}
			};

			jQuery(function($) {
				$('#id-disable-check').on('click', function() {
					var inp = $('#form-input-readonly').get(0);
					if(inp.hasAttribute('disabled')) {
						inp.setAttribute('readonly', 'true');
						inp.removeAttribute('disabled');
						inp.value = "This text field is readonly!";
					} else {
						inp.setAttribute('disabled', 'disabled');
						inp.removeAttribute('readonly');
						inp.value = "This text field is disabled!";
					}
				});

				//setSelect();

				$('[data-rel=tooltip]').tooltip({
					container: 'body'
				});
				$('[data-rel=popover]').popover({
					container: 'body'
				});

				autosize($('textarea[class*=autosize]'));

				$('textarea.limited').inputlimiter({
					remText: '%n character%s remaining...',
					limitText: 'max allowed : %n.'
				});

				$.mask.definitions['~'] = '[+-]';
				$('.input-mask-date').mask('99/99/9999');
				$('.input-mask-phone').mask('(999) 999-9999');
				$('.input-mask-eyescript').mask('~9.99 ~9.99 999');
				$(".input-mask-product").mask("a*-999-a999", {
					placeholder: " ",
					completed: function() {
						alert("You typed the following: " + this.val());
					}
				});

				$("#input-size-slider").css('width', '200px').slider({
					value: 1,
					range: "min",
					min: 1,
					max: 8,
					step: 1,
					slide: function(event, ui) {
						var sizing = ['', 'input-sm', 'input-lg', 'input-mini', 'input-small', 'input-medium', 'input-large', 'input-xlarge', 'input-xxlarge'];
						var val = parseInt(ui.value);
						$('#form-field-4').attr('class', sizing[val]).attr('placeholder', '.' + sizing[val]);
					}
				});

				$("#input-span-slider").slider({
					value: 1,
					range: "min",
					min: 1,
					max: 12,
					step: 1,
					slide: function(event, ui) {
						var val = parseInt(ui.value);
						$('#form-field-5').attr('class', 'col-xs-' + val).val('.col-xs-' + val);
					}
				});

				//"jQuery UI Slider"
				//range slider tooltip example
				$("#slider-range").css('height', '200px').slider({
					orientation: "vertical",
					range: true,
					min: 0,
					max: 100,
					values: [17, 67],
					slide: function(event, ui) {
						var val = ui.values[$(ui.handle).index() - 1] + "";

						if(!ui.handle.firstChild) {
							$("<div class='tooltip right in' style='display:none;left:16px;top:-6px;'><div class='tooltip-arrow'></div><div class='tooltip-inner'></div></div>")
								.prependTo(ui.handle);
						}
						$(ui.handle.firstChild).show().children().eq(1).text(val);
					}
				}).find('span.ui-slider-handle').on('blur', function() {
					$(this.firstChild).hide();
				});

				$("#slider-range-max").slider({
					range: "max",
					min: 1,
					max: 10,
					value: 2
				});

				$("#slider-eq > span").css({
					width: '90%',
					'float': 'left',
					margin: '15px'
				}).each(function() {
					// read initial values from markup and remove that
					var value = parseInt($(this).text(), 10);
					$(this).empty().slider({
						value: value,
						range: "min",
						animate: true

					});
				});

				$("#slider-eq > span.ui-slider-purple").slider('disable'); //disable third item

				$('#id-input-file-1 , #id-input-file-2').ace_file_input({
					no_file: 'No File ...',
					btn_choose: 'Choose',
					btn_change: 'Change',
					droppable: false,
					onchange: null,
					thumbnail: false //| true | large
					//whitelist:'gif|png|jpg|jpeg'
					//blacklist:'exe|php'
					//onchange:''
					//
				});
				//pre-show a file name, for example a previously selected file
				//$('#id-input-file-1').ace_file_input('show_file_list', ['myfile.txt'])

				$('#files').ace_file_input({
					style: 'well',
					btn_choose: 'Drop files here or click to choose',
					btn_change: null,
					no_icon: 'ace-icon fa fa-cloud-upload',
					droppable: true,
					thumbnail: 'small' //large | fit
						//,icon_remove:null//set null, to hide remove/reset button
						/**,before_change:function(files, dropped) {
							//Check an example below
							//or examples/file-upload.html
							return true;
						}*/
						/**,before_remove : function() {
							return true;
						}*/
						,
					preview_error: function(filename, error_code) {
						//name of the file that failed
						//error_code values
						//1 = 'FILE_LOAD_FAILED',
						//2 = 'IMAGE_LOAD_FAILED',
						//3 = 'THUMBNAIL_FAILED'
						//alert(error_code);
					}

				}).on('change', function() {
					//console.log($(this).data('ace_input_files'));
					//console.log($(this).data('ace_input_method'));
				});

				//$('#files')
				//.ace_file_input('show_file_list', [
				//{type: 'image', name: 'name of image', path: 'http://path/to/image/for/preview'},
				//{type: 'file', name: 'hello.txt'}
				//]);

				//dynamically change allowed formats by changing allowExt && allowMime function
				$('#id-file-format').removeAttr('checked').on('change', function() {
					var whitelist_ext, whitelist_mime;
					var btn_choose
					var no_icon
					if(this.checked) {
						btn_choose = "Drop images here or click to choose";
						no_icon = "ace-icon fa fa-picture-o";

						whitelist_ext = ["jpeg", "jpg", "png", "gif", "bmp"];
						whitelist_mime = ["image/jpg", "image/jpeg", "image/png", "image/gif", "image/bmp"];
					} else {
						btn_choose = "Drop files here or click to choose";
						no_icon = "ace-icon fa fa-cloud-upload";

						whitelist_ext = null; //all extensions are acceptable
						whitelist_mime = null; //all mimes are acceptable
					}
					var file_input = $('#files');
					file_input
						.ace_file_input('update_settings', {
							'btn_choose': btn_choose,
							'no_icon': no_icon,
							'allowExt': whitelist_ext,
							'allowMime': whitelist_mime
						})
					file_input.ace_file_input('reset_input');

					file_input
						.off('file.error.ace')
						.on('file.error.ace', function(e, info) {
							//console.log(info.file_count);//number of selected files
							//console.log(info.invalid_count);//number of invalid files
							//console.log(info.error_list);//a list of errors in the following format

							//info.error_count['ext']
							//info.error_count['mime']
							//info.error_count['size']

							//info.error_list['ext']  = [list of file names with invalid extension]
							//info.error_list['mime'] = [list of file names with invalid mimetype]
							//info.error_list['size'] = [list of file names with invalid size]

							/**
							if( !info.dropped ) {
								//perhapse reset file field if files have been selected, and there are invalid files among them
								//when files are dropped, only valid files will be added to our file array
								e.preventDefault();//it will rest input
							}
							*/

							//if files have been selected (not dropped), you can choose to reset input
							//because browser keeps all selected files anyway and this cannot be changed
							//we can only reset file field to become empty again
							//on any case you still should check files with your server side script
							//because any arbitrary file can be uploaded by user and it's not safe to rely on browser-side measures
						});

					/**
					file_input
					.off('file.preview.ace')
					.on('file.preview.ace', function(e, info) {
						console.log(info.file.width);
						console.log(info.file.height);
						e.preventDefault();//to prevent preview
					});
					*/

				});

				$('#spinner1').ace_spinner({
						value: 0,
						min: 0,
						max: 200,
						step: 10,
						btn_up_class: 'btn-info',
						btn_down_class: 'btn-info'
					})
					.closest('.ace-spinner')
					.on('changed.fu.spinbox', function() {
						//console.log($('#spinner1').val())
					});
				$('#spinner2').ace_spinner({
					value: 0,
					min: 0,
					max: 10000,
					step: 100,
					touch_spinner: true,
					icon_up: 'ace-icon fa fa-caret-up bigger-110',
					icon_down: 'ace-icon fa fa-caret-down bigger-110'
				});
				$('#spinner3').ace_spinner({
					value: 0,
					min: -100,
					max: 100,
					step: 10,
					on_sides: true,
					icon_up: 'ace-icon fa fa-plus bigger-110',
					icon_down: 'ace-icon fa fa-minus bigger-110',
					btn_up_class: 'btn-success',
					btn_down_class: 'btn-danger'
				});
				$('#spinner4').ace_spinner({
					value: 0,
					min: -100,
					max: 100,
					step: 10,
					on_sides: true,
					icon_up: 'ace-icon fa fa-plus',
					icon_down: 'ace-icon fa fa-minus',
					btn_up_class: 'btn-purple',
					btn_down_class: 'btn-purple'
				});

				//$('#spinner1').ace_spinner('disable').ace_spinner('value', 11);
				//or
				//$('#spinner1').closest('.ace-spinner').spinner('disable').spinner('enable').spinner('value', 11);//disable, enable or change value
				//$('#spinner1').closest('.ace-spinner').spinner('value', 0);//reset to 0

				//datepicker plugin
				//link
				$('.date-picker').datepicker({
						autoclose: true,
						todayHighlight: true
					})
					//show datepicker when clicking on the icon
					.next().on(ace.click_event, function() {
						$(this).prev().focus();
					});

				//or change it into a date range picker
				$('.input-daterange').datepicker({
					autoclose: true
				});

				//to translate the daterange picker, please copy the "examples/daterange-fr.js" contents here before initialization
				$('input[name=date-range-picker]').daterangepicker({
						'applyClass': 'btn-sm btn-success',
						'cancelClass': 'btn-sm btn-default',
						locale: {
							applyLabel: 'Apply',
							cancelLabel: 'Cancel',
						}
					})
					.prev().on(ace.click_event, function() {
						$(this).next().focus();
					});

				$('#timepicker1').timepicker({
					minuteStep: 1,
					showSeconds: true,
					showMeridian: false,
					disableFocus: true,
					icons: {
						up: 'fa fa-chevron-up',
						down: 'fa fa-chevron-down'
					}
				}).on('focus', function() {
					$('#timepicker1').timepicker('showWidget');
				}).next().on(ace.click_event, function() {
					$(this).prev().focus();
				});

				if(!ace.vars['old_ie']) $('#date-timepicker1').datetimepicker({
					//format: 'MM/DD/YYYY h:mm:ss A',//use this option to display seconds
					icons: {
						time: 'fa fa-clock-o',
						date: 'fa fa-calendar',
						up: 'fa fa-chevron-up',
						down: 'fa fa-chevron-down',
						previous: 'fa fa-chevron-left',
						next: 'fa fa-chevron-right',
						today: 'fa fa-arrows ',
						clear: 'fa fa-trash',
						close: 'fa fa-times'
					}
				}).next().on(ace.click_event, function() {
					$(this).prev().focus();
				});

				$('#colorpicker1').colorpicker();
				//$('.colorpicker').last().css('z-index', 2000);//if colorpicker is inside a modal, its z-index should be higher than modal'safe

				$('#simple-colorpicker-1').ace_colorpicker();
				//$('#simple-colorpicker-1').ace_colorpicker('pick', 2);//select 2nd color
				//$('#simple-colorpicker-1').ace_colorpicker('pick', '#fbe983');//select #fbe983 color
				//var picker = $('#simple-colorpicker-1').data('ace_colorpicker')
				//picker.pick('red', true);//insert the color if it doesn't exist

				$(".knob").knob();

				var tag_input = $('#form-field-tags');
				try {
					tag_input.tag({
						placeholder: tag_input.attr('placeholder'),
						//enable typeahead by specifying the source array
						source: ace.vars['US_STATES'], //defined in ace.js >> ace.enable_search_ahead
						/**
						//or fetch data from database, fetch those that match "query"
						source: function(query, process) {
						  $.ajax({url: 'remote_source.php?q='+encodeURIComponent(query)})
						  .done(function(result_items){
							process(result_items);
						  });
						}
						*/
					})

					//programmatically add/remove a tag
					var $tag_obj = $('#form-field-tags').data('tag');
					$tag_obj.add('Programmatically Added');

					var index = $tag_obj.inValues('some tag');
					$tag_obj.remove(index);
				} catch(e) {
					//display a textarea for old IE, because it doesn't support this plugin or another one I tried!
					tag_input.after('<textarea id="' + tag_input.attr('id') + '" name="' + tag_input.attr('name') + '" rows="3">' + tag_input.val() + '</textarea>').remove();
					//autosize($('#form-field-tags'));
				}

				/////////
				$('#modal-form input[type=file]').ace_file_input({
					style: 'well',
					btn_choose: 'Drop files here or click to choose',
					btn_change: null,
					no_icon: 'ace-icon fa fa-cloud-upload',
					droppable: true,
					thumbnail: 'large'
				})

				//chosen plugin inside a modal will have a zero width because the select element is originally hidden
				//and its width cannot be determined.
				//so we set the width after modal is show
				$('#modal-form').on('shown.bs.modal', function() {
					if(!ace.vars['touch']) {
						$(this).find('.chosen-container').each(function() {
							$(this).find('a:first-child').css('width', '210px');
							$(this).find('.chosen-drop').css('width', '210px');
							$(this).find('.chosen-search input').css('width', '200px');
						});
					}
				})
				/**
				//or you can activate the chosen plugin after modal is shown
				//this way select element becomes visible with dimensions and chosen works as expected
				$('#modal-form').on('shown', function () {
					$(this).find('.modal-chosen').chosen();
				})
				*/

				$(document).one('ajaxloadstart.page', function(e) {
					autosize.destroy('textarea[class*=autosize]')

					$('.limiterBox,.autosizejs').remove();
					$('.daterangepicker.dropdown-menu,.colorpicker.dropdown-menu,.bootstrap-datetimepicker-widget.dropdown-menu').remove();
				});

			});
		</script>
	</body>

</html>